"""from collections import defaultdict

dd = defaultdict(list)  # 默认值为空列表
dd["colors"].append("red")
dd["colors"].append("blue")

print(dd)  # defaultdict(<class 'list'>, {'colors': ['red', 'blue']})
"""

from collections import Counter

words = ["人工智能", "计算机科学", "分支", "创建", "系统"]
total_words = len(words)  # 5
word_count = Counter(words)

print(word_count)
for word, count in word_count.items():
    print(word, count)
    print(count / total_words)  # tf值
result = {word: count / total_words for word, count in word_count.items()}
print(result)
# {'人工智能': 0.2, '计算机科学': 0.2, '分支': 0.2, '创建': 0.2, '系统': 0.2}
